package com.yowasa.xiuxian.engine.battle.enemy.strategy;

import com.yowasa.xiuxian.annoations.BS;
import com.yowasa.xiuxian.engine.battle.strategy.BaseSpellStrategy;
import com.yowasa.xiuxian.entity.bo.battle.BattleContent;
import com.yowasa.xiuxian.entity.bo.battle.UserBattleContent;
import com.yowasa.xiuxian.entity.bo.user.UserBO;
import com.yowasa.xiuxian.entity.enums.ElementEnum;
import com.yowasa.xiuxian.service.helper.BattleHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@BS(name = "黑蛇之噬")
@Order(100)
@Component
public class HeiSheZhiShi extends BaseSpellStrategy {
    @Autowired
    private BattleHelper battleHelper;

    @Override
    public ElementEnum getElement() {
        return null;
    }

    @Override
    public void action(UserBattleContent first, UserBattleContent second, BattleContent content) {
        int needHp = first.getBattleInfo().getHp() - first.getBattleInfo().getChp();

        int orgAtk = first.getBattleInfo().getRes();
        int def = second.getBattleInfo().getRes();
        int atk = first.getBattleInfo().getSpell() + orgAtk * 2;
        int dmg = battleHelper.calAtk(atk, def);

        battleHelper.autoAction(this, first, second, content, dmg, "黑蛇之噬");
        int can = (int) ((dmg * 0.4) *first.getBattleInfo().getRestoreRate()/100);
        first.getBattleInfo().setChp(first.getBattleInfo().getChp() + Math.min(needHp,can));

        content.getMsgLog().add(first.getUserBO().getName() + "因黑蛇之噬回复" + can + "点血量");
        first.getCd().put("黑蛇之噬", 5);
    }

    @Override
    public void limit(UserBO user) {}

    @Override
    public String limitDesc() {
        return "无";
    }

    @Override
    public String desc() {
        return "陷阵之士，有死无生，地下古国曾经骄傲的军人，使用黑蛇的力量，造成自身法抗2倍的法术伤害，并回复此次伤害0.4的血量，cd5回合，战斗5回合后可释放";
    }

    @Override
    public boolean check(UserBattleContent user, BattleContent content) {
        if(content.getTurn() < 5){
            return false;
        }
        Integer cd = user.getCd().get("黑蛇之噬");
        if (cd != null && cd > 0) {
            return false;
        }
        return true;
    }


}
